import request from '@/utils/request';

/**
 * 获取部门详情
 * @param {string} id
 * @returns
 */
export const getDepartDetail = (id, loadingOptions) =>
  request({
    method: 'GET',
    url: `/company/department/${id}`,
    loadingOptions,
  });

/**
 * 新增部门
 * @param {object} data 
 *  {
      "code": "1001",
      "introduce": "部门介绍",
      "manager": "部门负责人名称",
      "name": "部门名称",
      "pid": "父级部门id"
    }
 * @param {object} loadingOptions 加载选项
 * @returns 
 */
export const addDepartment = (data, loadingOptions) => {
  return request({
    method: 'POST',
    url: '/company/department',
    data,
    loadingOptions,
  });
};

/**
 * 获取部门列表
 * @param {object} loadingOptions 加载选项
 * @returns
 */
export function getDepartments(loadingOptions) {
  return request({
    method: 'GET',
    url: '/company/department',
    loadingOptions, // axios 的请求配置对象除了内置的选项以外，还可以自定义一些选项
  });
}

/**
 * 根据 id 删除部门
 * @param {string} id 部门 id
 * @returns
 */
export function delDepartment(id) {
  return request({
    method: 'DELETE',
    url: `/company/department/${id}`,
  });
}
